package org.example.algorithm.greedy;

public class MaxProfitSolution {

    public int maxProfit(int[] prices) {
        int max = 0;
        int buyPrice = 0;
        for (int i=0;i<prices.length;i++) {
            if (i == 0) {
                buyPrice = prices[i];
            } else {
                max = Math.max(max, prices[i] - buyPrice);
                buyPrice = Math.min(buyPrice, prices[i]);
            }
        }
        return max;
    }
}
